package com.per.mybootall.thread;

import org.springframework.stereotype.Component;

@Component
public class MyThread implements Runnable {
private String name;

    public MyThread() {
    }

    public MyThread(String name) {
        this.name = name;
    }

    @Override
    public void run() {
        for(int i=0;i<=5;i++){
            if(i==2){
                //使用 yield() 方法将一个线程的操作暂时让给其他线程执行
                System.out.print("线程礼让：") ;
                Thread.currentThread().yield() ;    // 线程礼让
                             }
            System.out.print(name+":"+i+"          ");
        }

    }
}
